package cn.iocoder.yudao.module.trade.order.mq;

import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.module.api.trade.order.dto.TradeOrderItemRespDTO;
import cn.iocoder.yudao.module.api.trade.order.dto.TradeOrderRespDTO;
import cn.iocoder.yudao.module.api.trade.order.message.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 交易订单 事件生产者
 *
 * @author 山野羡民
 */
@Slf4j
@Component
public class TradeOrderProducer {

    /**
     * 发送 {@link TradeOrderCreatedMessage} 消息
     *
     * @param order 交易订单信息
     */
    public void sendTradeOrderCreatedMessage(TradeOrderRespDTO order, List<TradeOrderItemRespDTO> orderItems) {
        log.info("[sendTradeOrderCreatedMessage] {} {}", order, orderItems);
        SpringUtil.getApplicationContext().publishEvent(new TradeOrderCreatedMessage(order, orderItems));
    }

    /**
     * 发送 {@link TradeOrderPaidMessage} 消息
     *
     * @param order 交易订单信息
     */
    public void sendTradeOrderPaidMessage(TradeOrderRespDTO order) {
        log.info("[sendTradeOrderPaidMessage] {}", order);
        SpringUtil.getApplicationContext().publishEvent(new TradeOrderPaidMessage(order));
    }

    /**
     * 发送 {@link TradeOrderDeliveryMessage} 消息
     *
     * @param order 交易订单信息
     */
    public void sendTradeOrderDeliveryMessage(TradeOrderRespDTO order) {
        log.info("[sendTradeOrderDeliveryMessage] {}", order);
        SpringUtil.getApplicationContext().publishEvent(new TradeOrderDeliveryMessage(order));
    }

    /**
     * 发送 {@link TradeOrderCompletedMessage} 消息
     *
     * @param order 交易订单信息
     */
    public void sendTradeOrderCompletedMessage(TradeOrderRespDTO order) {
        log.info("[sendTradeOrderCompletedMessage] {}", order);
        SpringUtil.getApplicationContext().publishEvent(new TradeOrderCompletedMessage(order));
    }

    public void sendTradeAfterSaleCompletedMessage(TradeOrderRespDTO order, TradeOrderItemRespDTO orderItem) {
        log.info("[sendTradeAfterSaleCompletedMessage] {}", order);
        SpringUtil.getApplicationContext().publishEvent(new TradeAfterSaleCompletedMessage(order, orderItem));
    }

}
